﻿using System;

namespace SilverChart.Core.Configuration {
    /// <summary>
    /// Mark a class is Configuration Item. 
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, Inherited=false)]
    public class ConfigurationItemAttribute: Attribute {
        private Type parent;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name">Configuration Item name</param>
        public ConfigurationItemAttribute(String name) {
            if (name == null || name.Trim().Length <= 0) {
                throw new ArgumentException("name attribute must be specified");
            }
            Name = name;
            IsRootItem = false;
            CreateForDefault = false;
        }

        /// <summary>
        /// Mark whether this Item is ROOT configuration item.
        /// </summary>
        public Boolean IsRootItem { get; set; }

        /// <summary>
        /// If this element does not exist in Configuration, whether create default Item for it.
        /// </summary>
        public Boolean CreateForDefault { get; set; }

        /// <summary>
        /// Parent Configuration Item class type.
        /// </summary>
        public Type Parent {
            get {
                return parent;
            }
            set {
                if (value != null && !typeof(ConfigurationItem).IsAssignableFrom(value)) {
                    throw new ArgumentException("parent must be derived from ConfigurationItem");
                }
                parent = value;
            }
        }

        /// <summary>
        /// Configuration Item name
        /// </summary>
        public String Name { get; private set; }
    }
}
